// pages/my/my.js
var api = require("../../config/api.js")
var app = getApp();
Page({
    data: {
      my_dynamic_num:'暂无',
      my_follow:'暂无',
      my_fans:'暂无',
      src_path:'https://b.yzcdn.cn/vant/icon-demo-1126.png',
      phone:'',
        username:' 点击登录或注册',
      show: false,
      is_active:'',
      actions: [
        {
          name: '选项',
        },
        {
          name: '选项',
        },
        {
          name: '选项',
          subname: '描述信息',
          openType: 'share',
        },
      ],
    },
    tiaozhuanxiangxi:function(){
      console.log('跳转/pages/search/search')
      if(app.globalData.token==null){
        wx.showToast({
          title: '您还没有登录',
          icon: 'error',
        })
      }else{
      wx.navigateTo({
        url: '../../pages/news/news?' +'token='+app.globalData.token,
      })
    }
    },
    onClickLogin:function(){
        console.log('点击登录或注册', this.data.nickname)
        if (!this.data.nickname||this.data.nickname == " 点击登录或注册"){
        //跳转
        wx.navigateTo({
            url: "/pages/login/login",
          })
        }wx.login({
            timeout: 0,
            success: (result) => {
                console.log(result.code)
            },
            fail: (res) => {},
            complete: (res) => {},
          })
        

    },
    onClose() {
      this.setData({ show: false });
    },
  
    onSelect(event) {
      console.log(event.detail);
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      console.log('aaa', app.globalData)
      this.setData({
        is_active : app.globalData.is_active,
        phone:app.globalData.phone,
        username:app.globalData.username
      })
    },
    onLogOut:function(){
      console.log('退出登录')
      // this.setData({
      //   phone:'',
      //   username:' 点击登录或注册',
      // is_active:''
      // })
      this.setData({
        src_path:'https://b.yzcdn.cn/vant/icon-demo-1126.png',
      })
      app.globalData.username='点击登录或注册',
      app.globalData.password='',
      app.globalData.phone= '',
      app.globalData.token= '',
      wx.setStorageSync('Logintokenkey', '')
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
      this.setData({
        is_active : app.globalData.is_active,
        phone:app.globalData.phone,
        username:app.globalData.username
      })
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
      if (app.globalData.avatar){
        this.setData({
          src_path:app.globalData.avatar
        })
      }
      this.setData({
        is_active : app.globalData.is_active,
        phone:app.globalData.phone,
        username:app.globalData.username
      })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})